package com.houg.testuserapi.common.constants;

/**
 * @Author: NALHOUG
 * @Time: 2019/11/8 14:59
 * @Explain:
 */

public enum ResultCode {
    //成功
    SUCCESS(10000, "成功"),
    VERIFICATION_CODE_ERROR(10001, "验证码错误"),
    LOGIN_SUCCESS(10002,"登录成功"),
    LOGOUT_SUCCESS(10003,"用户退出登录"),
    ACCOUNT_REGISTER_SUCCESS(10004, "注册成功"),


    //错误
    ERROR(20000, "失败"),
    ACCOUNT_NOT_EXIST(20001, "用户不存在"),
    LOGIN_PASSWORD_ERROR(20002, "用户密码错误"),
    ACCOUNT_REGISTER_ERROR(20003, "用户注册错误"),
    ACCOUNT_HAS_USERNAME(20004, "账号已被注册"),
    HAS_EXISTED(20005, "用户已存在"),
    PARAM_IS_NULL(20006, "参数为空"),

    //权限
    NOT_LOGGED_IN(30000, "用户未登录"),
    ACCOUNT_OFF(30001, "账号已自行注销"),
    ACCOUNT_FORBIDDEN(30002, "账号已被禁用"),
    ACCOUNT_EXCEPTION(30003, "账号状态异常"),
    SESSION_TIME_OUT(30004, "Session超时"),



    //系统
    SYSTEM_INNER_ERROR(40000, "系统繁忙，请稍后重试");

    /**
     * 属性和构造方法
     */
    private Integer code;

    private String message;

    ResultCode(Integer code, String message) {
        this.code = code;
        this.message = message;
    }

    public Integer code() {
        return this.code;
    }

    public String message() {
        return this.message;
    }

    public static String getMessage(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.message;
            }
        }
        return name;
    }

    public static Integer getCode(String name) {
        for (ResultCode item : ResultCode.values()) {
            if (item.name().equals(name)) {
                return item.code;
            }
        }
        return null;
    }

    @Override
    public String toString() {
        return this.name();
    }

}

